<?php
//模型
class MemberModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'user';
	}
	
	function get_list($arr=array(),$page=1,$size=10){
		
		$where = "1";
		
		if(isset($arr['keyword']) && !empty($arr['keyword'])){
			$where .= " AND (nickname like '{$arr['keyword']}%' OR mobile like '{$arr['keyword']}%' )";
		}
		
		
		if(isset($arr['uids']) && !empty($arr['uids'])){
			$ids = implode(',',$arr['uids']);
			if(!empty($ids)){
				$where .= " AND id in({$ids})";
			}
			
		}
		
		if(isset($arr['cid']) && !empty($arr['cid'])){
			$sql  = "select user_id from ".$this->db->dbprefix."user_card  where cid ='{$arr['cid']}' AND num>0 limit 1000";
			$query = $this->db->query($sql);
			$res = $query->result_array();
			$ids_arr = array('0');
			foreach($res as $val){
				$ids_arr[] = $val['user_id'];
			}
			$ids = implode(',',$ids_arr);
			$where .= " AND id in({$ids})";
		}
		

		$res = $this->Member->_where_get_list($where,$page,$size);
		$list = $res['list'];
		
		if($list){
			foreach($list as $key=>$val){
				$list[$key]['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
				unset($list[$key]['openid']);
				
				$list[$key]['headimg'] = image_path($val['headimg']);
				
			}
		}
		
		return array('list'=>$list,'count'=>$res['count']);
	}
	
	function get_info($id){
		$info = $this->_id_get_info($id);
		if(!$info){
			return false;
		}
		unset($info['openid']);
		
		return $info;
	}

}

